package com.magina.mq.listener;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

@Component
public class QueueListener {

    @Value("${act.queueName}")
    private String actQueueName;

    //中转的queue
    private static final  String CONVERT_QUEUE_STR = "out.queue";

    @JmsListener(destination = "${act.queueName}", containerFactory = "jmsListenerContainerQueue")
    @SendTo(CONVERT_QUEUE_STR)
    public String receive(String text){
        String resultStr  = "ActiveMq:"+actQueueName+" consumer 收到一条信息: " + text;
        System.out.println(resultStr);
        return text;
    }

    @JmsListener(destination = CONVERT_QUEUE_STR)
    public void consumerMsg(String msg){
        String resultStr  = "ActiveMq:"+CONVERT_QUEUE_STR+" consumer 收到一条信息: " + msg;
        System.out.println(resultStr);
    }
}